local stock_key = KEYS[1]
local sku_id = KEYS[2]
local deduct_num = ARGV[1]

local current = redis.call('HGET', stock_key, sku_id)


if deduct_num == nil then
    return redis.error_reply('deduct_num not nil')
end

if current == false then
    return redis.error_reply('key not found')
end

if current == nil then
    return redis.error_reply('current value is not a number')
end

local available = tonumber(current)
local available1 = tonumber(deduct_num)


if available < available1 then
    return -1
end

return redis.call('HINCRBY', stock_key, sku_id, -deduct_num)
